<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        div{
            width: 200px;
            height: 100px;
            border: 1px solid red;
        }
    </style>
</head>
<body>
    <button>点击我发送请求</button>
    <div>

    </div>
    <script>
        let button = document.querySelector('button')
        let div = document.querySelector('div');
        // console.log(div);
        button.onclick = function(){
            let ajax = new XMLHttpRequest()
            ajax.open('get','http://127.0.0.1:9700/serve?a=299&b=199&c=99',true)
            ajax.send()
            // readystate  有0 1 2 3 4 
            // 0   表示未初始化 
            // 1   表示open方法已经完毕
            // 2   表示send方法已经完毕
            // 3   表示返回了部分数据
            // 4   表示返回了全部数据
            ajax.onreadystatechange = function (){
                if(ajax.readyState === 4){
                    if (ajax.status == 200) {
                            div.innerHTML=ajax.response
                            console.log(ajax.status);  //获取状态码
                            console.log(ajax.statusText); //获取状态字符串
                            console.log(ajax.getAllResponseHeaders()); //获取所有响应头
                            console.log(ajax.response);  //响应体
                    }
                }
            }
        }
    </script>
</body>
</html>